package com.example.app;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

public class Ellipse extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ellipse);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }

    public void ellipseCalcClick(View view){
        EditText area = (EditText) findViewById(R.id.areaellipse);
        String arhString = area.getText().toString();
        EditText minor = (EditText) findViewById(R.id.a);
        String aString = minor.getText().toString();
        EditText major = (EditText) findViewById(R.id.b);
        String bString = major.getText().toString();
        EditText focal = (EditText) findViewById(R.id.f);
        String fhString = focal.getText().toString();
        EditText eccentricity = (EditText) findViewById(R.id.e);
        double arh;
        double fh;
        double eh;
        double ah;
        double bh;
        if (arhString == null || arhString.isEmpty()){
            arh = 0.0;
        }else{
            arh = Double.parseDouble(arhString);
        }
        if (aString == null || aString.isEmpty()){
            ah = 0.0;
        }else{
            ah = Double.parseDouble(aString);
        }
        if (){

        }

        double a;
        double b;
        double e;
        double f;
        double ar;
        Double pi= Math.PI;
        CheckBox checkBox1 = (CheckBox) findViewById(R.id.a);
        if (checkBox1.isChecked()) {
            a = 1;
        }else{
            a = 0;
        }
        CheckBox checkBox2 = (CheckBox) findViewById(R.id.b);
        if (checkBox2.isChecked()) {
            b = 1;
        }else{
            b = 0;
        }
        CheckBox checkBox3 = (CheckBox) findViewById(R.id.f);
        if (checkBox3.isChecked()) {
            f = 1;
        }else{
            f = 0;
        }
        CheckBox checkBox4 = (CheckBox) findViewById(R.id.e);
        if (checkBox4.isChecked()) {
            e = 1;
        }else{
            e = 0;
        }
        CheckBox checkBox5 = (CheckBox) findViewById(R.id.areaellipse);
        if (checkBox5.isChecked()) {
            ar = 1;
        }else{
            ar = 0;
        }
        Double total = a+b+e+f+ar;
        if (total == 2){
            TextView warn = (TextView) findViewById(R.id.warningMessage);


            String mess = "";
            warn.setText(mess);
            Double thing = a+(b*2)+(f*4)+(e*8)+(ar*16);
            if (thing == 3){
                //semi major axis and semi minor axis to calculate

                arh = a*b*pi;
                arhString = arh+"";
                area.setText(arhString);
                fh = Math.sqrt((b * b) - (a * a));
                String fhString = fh+"";
                focal.setText(fhString);

            }
            if (thing == 5){
                //focal radius and semi minor axis to calculate
            }
            if (thing == 9){
                //eccentricity and semi minor axis to calculate
            }
            if (thing == 17){
                //area and semi minor axis to calculate
            }
            if (thing == 6){
                //semi major axis and focal radius to calculate
            }
            if (thing == 10){
                //semi major axis and eccentricity to calculate
            }
            if (thing == 18){
                //semi major axis and area to calculate
            }
            if (thing == 12){
                //focal radius and eccentricity to calculate
            }
            if (thing == 20){
                //focal radius and area to calculate
            }
            if (thing == 24){
                //eccentricity and area axis to calculate
            }
        }else{
            TextView warn = (TextView) findViewById(R.id.warningMessage);
            String mess = "There needs to be exactly two checked boxes";
            warn.setText(mess);
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.ellipse, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_ellipse, container, false);
            return rootView;
        }
    }

}
